﻿using Microsoft.Extensions.Configuration;
using MySqlConnector;
using System.Data;

namespace DapperDemo.Infrastructure;

public class BaseRepository : IBaseRepository
{
    private readonly IConfiguration _configuration;

    public BaseRepository(IConfiguration configuration)
    {
        _configuration = configuration;
    }

    public IDbConnection GetOpenConn()
    {
        IDbConnection con = null;
        var connectionString = _configuration.GetConnectionString("Default");
        con = new MySqlConnection(connectionString);
        try
        {
            con.Open();
        }
        catch (Exception ex)
        {
            throw new Exception("数据库连接错误:" + ex.Message);
        }

        return con;
    }
}